using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_QUTMASTER
    {
        public DataRow Convert2ICC_QUTMASTER(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_QUTMASTER(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QUID"] = " ".PadRight(256 ); 
         dwReturn["QUORDER"] = " ".PadRight(256 ); 
         dwReturn["QULINE"] = " ".PadRight(256 ); 
         dwReturn["QUBOMID"] = " ".PadRight(256 ); 
         dwReturn["QUSUPNAME"] = " ".PadRight(256 ); 
         dwReturn["QUARTICLE"] = " ".PadRight(256 ); 
         dwReturn["QUVAR"] = " ".PadRight(256 ); 
         dwReturn["QUCOLOR"] = " ".PadRight(256 ); 
         dwReturn["QUFINISH"] = " ".PadRight(256 ); 
         dwReturn["QUJW"] = " ".PadRight(256 ); 
         dwReturn["QUSTAGE"] = " ".PadRight(256 ); 
         dwReturn["QUSTAGEDES"] = " ".PadRight(256 ); 
         dwReturn["QUSOURCETYPE"] = " ".PadRight(256 ); 
         dwReturn["QUFVALUE"] = " ".PadRight(256 ); 
         dwReturn["QUCVALUE"] = " ".PadRight(256 ); 
         dwReturn["QUPVALUE"] = " ".PadRight(256 ); 
         dwReturn["QUFQUANTITY"] = " ".PadRight(256 ); 
         dwReturn["QUUOM"] = " ".PadRight(256 ); 
         dwReturn["QUPTY1"] = " ".PadRight(256 ); 
         dwReturn["QUPTY2"] = " ".PadRight(256 ); 
         dwReturn["QUPTY3"] = " ".PadRight(256 ); 
         dwReturn["QUQTY1"] = " ".PadRight(256 ); 
         dwReturn["QUQTY2"] = " ".PadRight(256 ); 
         dwReturn["QUQTY3"] = " ".PadRight(256 ); 
         dwReturn["QUPPRICE"] = " ".PadRight(256 ); 
         dwReturn["QUCPRICE"] = " ".PadRight(256 ); 
         dwReturn["QUFPRICE"] = " ".PadRight(256 ); 
         dwReturn["QUSBOMID"] = " ".PadRight(256 ); 
         dwReturn["QUPRODCOST"] = " ".PadRight(256 ); 
         dwReturn["QUMATCOST"] = " ".PadRight(256 ); 
         dwReturn["QURATIO"] = " ".PadRight(256 ); 
         dwReturn["QUUSER"] = " ".PadRight(256 ); 
         dwReturn["QUDATE"] = " ".PadRight(256 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_QUTMASTER(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_QUTMASTER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_QUTMASTER(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_QUTMASTER(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_QUTMASTER(dwLocal, ITXDBVERSION);
            }
            UpdateICC_QUTMASTER(dwLocal);
        }
        public void InsertICC_QUTMASTER(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_QUTMASTER(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_QUTMASTER(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_QUTMASTER WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_QUTMASTER  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_QUTMASTER";
            Return = Result;
            return Return;
        }
        public void DeleteICC_QUTMASTER(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_QUTMASTER   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_QUTMASTER(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_QUTMASTER SET "
                    +"QUID= :QUID,"
                    +"QUORDER= :QUORDER,"
                    +"QULINE= :QULINE,"
                    +"QUBOMID= :QUBOMID,"
                    +"QUSUPNAME= :QUSUPNAME,"
                    +"QUARTICLE= :QUARTICLE,"
                    +"QUVAR= :QUVAR,"
                    +"QUCOLOR= :QUCOLOR,"
                    +"QUFINISH= :QUFINISH,"
                    +"QUJW= :QUJW,"
                    +"QUSTAGE= :QUSTAGE,"
                    +"QUSTAGEDES= :QUSTAGEDES,"
                    +"QUSOURCETYPE= :QUSOURCETYPE,"
                    +"QUFVALUE= :QUFVALUE,"
                    +"QUCVALUE= :QUCVALUE,"
                    +"QUPVALUE= :QUPVALUE,"
                    +"QUFQUANTITY= :QUFQUANTITY,"
                    +"QUUOM= :QUUOM,"
                    +"QUPTY1= :QUPTY1,"
                    +"QUPTY2= :QUPTY2,"
                    +"QUPTY3= :QUPTY3,"
                    +"QUQTY1= :QUQTY1,"
                    +"QUQTY2= :QUQTY2,"
                    +"QUQTY3= :QUQTY3,"
                    +"QUPPRICE= :QUPPRICE,"
                    +"QUCPRICE= :QUCPRICE,"
                    +"QUFPRICE= :QUFPRICE,"
                    +"QUSBOMID= :QUSBOMID,"
                    +"QUPRODCOST= :QUPRODCOST,"
                    +"QUMATCOST= :QUMATCOST,"
                    +"QURATIO= :QURATIO,"
                    +"QUUSER= :QUUSER,"
                    +"QUDATE= :QUDATE,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QUID", OracleType.NVarChar).Value = dwData["QUID"].ToString(); 
          or1.Parameters.Add("QUORDER", OracleType.NVarChar).Value = dwData["QUORDER"].ToString(); 
          or1.Parameters.Add("QULINE", OracleType.NVarChar).Value = dwData["QULINE"].ToString(); 
          or1.Parameters.Add("QUBOMID", OracleType.NVarChar).Value = dwData["QUBOMID"].ToString(); 
          or1.Parameters.Add("QUSUPNAME", OracleType.NVarChar).Value = dwData["QUSUPNAME"].ToString(); 
          or1.Parameters.Add("QUARTICLE", OracleType.NVarChar).Value = dwData["QUARTICLE"].ToString(); 
          or1.Parameters.Add("QUVAR", OracleType.NVarChar).Value = dwData["QUVAR"].ToString(); 
          or1.Parameters.Add("QUCOLOR", OracleType.NVarChar).Value = dwData["QUCOLOR"].ToString(); 
          or1.Parameters.Add("QUFINISH", OracleType.NVarChar).Value = dwData["QUFINISH"].ToString(); 
          or1.Parameters.Add("QUJW", OracleType.NVarChar).Value = dwData["QUJW"].ToString(); 
          or1.Parameters.Add("QUSTAGE", OracleType.NVarChar).Value = dwData["QUSTAGE"].ToString(); 
          or1.Parameters.Add("QUSTAGEDES", OracleType.NVarChar).Value = dwData["QUSTAGEDES"].ToString(); 
          or1.Parameters.Add("QUSOURCETYPE", OracleType.NVarChar).Value = dwData["QUSOURCETYPE"].ToString(); 
          or1.Parameters.Add("QUFVALUE", OracleType.NVarChar).Value = dwData["QUFVALUE"].ToString(); 
          or1.Parameters.Add("QUCVALUE", OracleType.NVarChar).Value = dwData["QUCVALUE"].ToString(); 
          or1.Parameters.Add("QUPVALUE", OracleType.NVarChar).Value = dwData["QUPVALUE"].ToString(); 
          or1.Parameters.Add("QUFQUANTITY", OracleType.NVarChar).Value = dwData["QUFQUANTITY"].ToString(); 
          or1.Parameters.Add("QUUOM", OracleType.NVarChar).Value = dwData["QUUOM"].ToString(); 
          or1.Parameters.Add("QUPTY1", OracleType.NVarChar).Value = dwData["QUPTY1"].ToString(); 
          or1.Parameters.Add("QUPTY2", OracleType.NVarChar).Value = dwData["QUPTY2"].ToString(); 
          or1.Parameters.Add("QUPTY3", OracleType.NVarChar).Value = dwData["QUPTY3"].ToString(); 
          or1.Parameters.Add("QUQTY1", OracleType.NVarChar).Value = dwData["QUQTY1"].ToString(); 
          or1.Parameters.Add("QUQTY2", OracleType.NVarChar).Value = dwData["QUQTY2"].ToString(); 
          or1.Parameters.Add("QUQTY3", OracleType.NVarChar).Value = dwData["QUQTY3"].ToString(); 
          or1.Parameters.Add("QUPPRICE", OracleType.NVarChar).Value = dwData["QUPPRICE"].ToString(); 
          or1.Parameters.Add("QUCPRICE", OracleType.NVarChar).Value = dwData["QUCPRICE"].ToString(); 
          or1.Parameters.Add("QUFPRICE", OracleType.NVarChar).Value = dwData["QUFPRICE"].ToString(); 
          or1.Parameters.Add("QUSBOMID", OracleType.NVarChar).Value = dwData["QUSBOMID"].ToString(); 
          or1.Parameters.Add("QUPRODCOST", OracleType.NVarChar).Value = dwData["QUPRODCOST"].ToString(); 
          or1.Parameters.Add("QUMATCOST", OracleType.NVarChar).Value = dwData["QUMATCOST"].ToString(); 
          or1.Parameters.Add("QURATIO", OracleType.NVarChar).Value = dwData["QURATIO"].ToString(); 
          or1.Parameters.Add("QUUSER", OracleType.NVarChar).Value = dwData["QUUSER"].ToString(); 
          or1.Parameters.Add("QUDATE", OracleType.NVarChar).Value = dwData["QUDATE"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
